#ifndef _R_BUF_H_ 
#define _R_BUF_H_ 

 
 
/////////////////////////////////////////////////////////////////////////////// 
typedef struct _r_buf { 
	unsigned int 	head; 
	unsigned int 	end; 
	unsigned int 	RbLen; 
	unsigned char	*buf; 
}R_buf, * pR_buf; 

#define	OS_DISABLE_INT()	disableInterrupts()	
#define	OS_ENABLE_INT()		enableInterrupts()
 
/////////////////////////////////////////////////////////////////////////////// 
///---------------------------------------------------------------------------- 
 // Judge ring buf is empty. 
///---------------------------------------------------------------------------- 
#define RbEmpty(rb) ((rb)->head == (rb)->end) 
 
///---------------------------------------------------------------------------- 
 // Judge ring buf is full. 
///---------------------------------------------------------------------------- 
#define RbFull(rb) (RbGetDatLen(rb) == ((rb)->RbLen - 1)) 
 
///---------------------------------------------------------------------------- 
 // Calculate ring buf free space length. 
///---------------------------------------------------------------------------- 
#define RbGetFree(rb) ((rb)->RbLen - RbFull(rb) - 1) 
 
///---------------------------------------------------------------------------- 
 // Calculate ring buf data length. 
///---------------------------------------------------------------------------- 
#define ABS(x) (((x) >= 0) ? (x) : ((x) * -1)) 
#define RbGetDatLen(rb) (int)(((rb)->head - (rb)->end+(rb)->RbLen)%(rb)->RbLen)
 	    //(rear - front + maxsize) % maxsize;  
 
/////////////////////////////////////////////////////////////////////////////// 


#define	TRUE	1
#define FALSE	0
#ifndef NULL
#define NULL (void*)0
#endif

int RbInit(pR_buf rb, unsigned char *pBuf, unsigned int  bLen); 
int RbReinit(pR_buf rb); 
int RbPush(pR_buf rb, unsigned char val); 
int RbPop(pR_buf rb, unsigned char * val); 
int RbInsrt(pR_buf rb, unsigned char *in, int inLen); 
int RbRemove(pR_buf rb, unsigned char *out, int outLen); 
int RbSearch(pR_buf rb, unsigned char ch, char newSearch); 
 
 
 
#endif 